<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id="connect">连接</button>
    <button id="send" >发送数据</button><br>
    从服务端接收数据如下：<br>
    <span id="res"></span>
    <script>
        var connect = document.querySelector("#connect");
        var send = document.querySelector("#send");
        var res = document.querySelector("#res");
        let ws = null;
        connect.onclick = function(){
             ws =new WebSocket("ws://localhost:9998")
        }
        send.onclick = function(){
            ws.onopen = ()=>{
                console.log('连接服务端成功')               
            }
            ws.onclose = ()=>{
                console.log('连接服务端失败')
            }
            ws.onmessage = (msg)=>{
                console.log('接收到服务端发来的数据')
                console.log(msg)
                res.innerHTML = msg.data
            }
            send.onclick = function(){
                ws.send(JSON.stringify({
                    action:'getData',
                    socketType:'trendData',
                    chartName:'trend',
                    value:''
                }))
            }
        }
    </script>
</body>
</html>